import java.util.List;

public class ProductIterator implements Iterator {
    private ProductList productList;
    private List<Object> products;
    private int currentIndex = 0;

    public ProductIterator(ProductList productList) {
        this.productList = productList;
        this.products = productList.getObjects();
    }

    @Override
    public void next() {
        if (currentIndex < products.size()) {
            currentIndex++;
        }
    }

    @Override
    public boolean isLast() {
        return currentIndex == products.size();
    }

    @Override
    public void previous() {
        if (currentIndex > 0) {
            currentIndex--;
        }
    }

    @Override
    public boolean isFirst() {
        return currentIndex == 0;
    }

    @Override
    public Object getNextItem() {
        return products.get(currentIndex);
    }

    @Override
    public Object getPreviousItem() {
        return products.get(currentIndex - 1);
    }
}
